package org.example.pms.controller;

import org.example.pms.domain.ClinicalObservation;
import org.example.pms.service.ClinicalObservationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/clinicalObservation")
public class ClinicalObservationController {

    @Resource
    ClinicalObservationService clinicalObservationService;

    /**
     * 根据id查询临床结果
     *
     * @param id 临床结果id
     * @return 临床结果
     */
    @GetMapping("/{id}")
    public ClinicalObservation getClinicalObservationById(@PathVariable Integer id) {
        return clinicalObservationService.selectById(id);
    }

    /**
     * 根据患者id查询临床结果集
     *
     * @param patientId 患者id
     * @return 临床结果集
     */
    @GetMapping("/results/{patientId}")
    public List<ClinicalObservation> getClinicalObservationByPatientId(@PathVariable Integer patientId) {
        List<ClinicalObservation> clinicalObservations = clinicalObservationService.selectByPatientId(patientId);
        return clinicalObservations;
    }

    /**
     * 增加临床结果
     *
     * @param clinicalObservation 临床结果
     * @return 临床结果自增id
     */
    @PostMapping()
    public Integer createClinicalObservation(@RequestBody ClinicalObservation clinicalObservation) {
        Integer id = clinicalObservationService.insert(clinicalObservation);
        return id;
    }

    @PutMapping("/{id}")
    public Integer updateClinicalObservation(@PathVariable Integer id, @RequestBody ClinicalObservation clinicalObservation) {
        clinicalObservation.setId(id);
        Integer idd = clinicalObservationService.update(clinicalObservation);
        return idd;
    }

    @DeleteMapping("/{id}")
    public Integer deleteClinicalObservation(@PathVariable Integer id) {
        Integer delete = clinicalObservationService.delete(id);
        return delete;
    }
}
